import { WeaSearchGroup,WeaFormItem,WeaBrowser,WeaLocaleProvider} from 'ecCom';
import { Button,Form } from 'antd';
import {toJS} from "mobx"
import {WeaSwitch} from "comsMobx"
import { inject, observer} from 'mobx-react';
const getLabel = WeaLocaleProvider.getLabel;

@observer
class Condition extends React.Component{

    render(){
        const { condition,  } = this.props.listStore;
        const {form,onEnterSearch} = this.props;
        const {isFormInit} = form;
        let group = [];
        isFormInit &&  toJS(condition).map((c,i) =>{
          let items = [];
          c.items.map((fields,index) => {
            items.push({
              com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@kkirfk@${index}`}
                  label={`${fields.label}`}
                  labelCol={{span: `${fields.labelcol}`}}
                  wrapperCol={{span: `${fields.fieldcol}`}}>
                    <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@w68b4l@${index}`} fieldConfig={fields} form={form} onEnterSearch={onEnterSearch} />
                  </WeaFormItem>),
              colSpan:1,
            })
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@pik55v@${i}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return group;
    }
}

const getAdButtons = (listStore,ecid) => {
	const {doSearch,setShowSearchAd,clearFormFields,setSelectedTreeKey} = listStore;
	return [
		(<Button ecId={`${ecid}_Button@qtw0ux@search`} type="primary" onClick={()=>{doSearch();setShowSearchAd(false);}}>{getLabel('388113','搜索') }</Button>),
		(<Button ecId={`${ecid}_Button@qu2bzb@reset`} type="ghost" onClick={()=>{clearFormFields();setSelectedTreeKey&&setSelectedTreeKey('-1')}}>{getLabel('2022','重置') }</Button>),
		(<Button ecId={`${ecid}_Button@yd54o2@cancel`} type="ghost" onClick={()=>{setShowSearchAd(false)}}>{getLabel('31129','取消') }</Button>)
	];
}

export {Condition,getAdButtons}
